﻿using Apps.Common;
using Apps.Models;
using Apps.Models.S;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Apps.BLL.S
{
    public partial class S_MAKESAMPLEBLL
    {
        public DBContainer db = new DBContainer();

        public List<V_S_MAKESAMPLEModel> GetList_RC(ref GridPager pager, string batch, 
            string startdate1, string startdate2, 
            string enddate1, string enddate2,
            string pTime1, string pTime2)
        {
            IQueryable<V_S_MAKESAMPLE_RC> queryData = this.db.V_S_MAKESAMPLE_RC.AsQueryable();
            if (!string.IsNullOrEmpty(batch))
            {
                queryData = queryData.Where(m => m.BATCH_CODE.Contains(batch));
            }
            if (!string.IsNullOrEmpty(startdate1))
            {
                DateTime dStartDate1 = DateTime.ParseExact(startdate1, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.BEGIN_TIME >= dStartDate1);
            }
            if (!string.IsNullOrEmpty(startdate2))
            {
                DateTime dStartDate2 = DateTime.ParseExact(startdate2, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.BEGIN_TIME < dStartDate2);
            }
            if (!string.IsNullOrEmpty(enddate1))
            {
                DateTime dEndDate1 = DateTime.ParseExact(enddate1, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.END_TIME >= dEndDate1);
            }
            if (!string.IsNullOrEmpty(enddate2))
            {
                DateTime dEndDate2 = DateTime.ParseExact(enddate2, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.END_TIME < dEndDate2);
            }

            if (!string.IsNullOrEmpty(pTime1))
            {
                DateTime dPTime1 = DateTime.ParseExact(pTime1, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.P_TIME >= dPTime1);
            }
            if (!string.IsNullOrEmpty(pTime2))
            {
                DateTime dPTime2 = DateTime.ParseExact(pTime2, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.P_TIME < dPTime2);
            }

            pager.totalRows = queryData.Count();
            //排序
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            return TransHelper.TransExpList<V_S_MAKESAMPLE_RC, V_S_MAKESAMPLEModel>(queryData.ToList());
        }

        public List<V_S_MAKESAMPLEModel> GetList_RL(ref GridPager pager, string batch,
            string startdate1, string startdate2,
            string enddate1, string enddate2,
            string pTime1, string pTime2)
        {
            IQueryable<V_S_MAKESAMPLE_RL> queryData = this.db.V_S_MAKESAMPLE_RL.AsQueryable();
            if (!string.IsNullOrEmpty(batch))
            {
                queryData = queryData.Where(m => m.BATCH_CODE.Contains(batch));
            }
            if (!string.IsNullOrEmpty(startdate1))
            {
                DateTime dStartDate1 = DateTime.ParseExact(startdate1, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.BEGIN_TIME >= dStartDate1);
            }
            if (!string.IsNullOrEmpty(startdate2))
            {
                DateTime dStartDate2 = DateTime.ParseExact(startdate2, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.BEGIN_TIME < dStartDate2);
            }
            if (!string.IsNullOrEmpty(enddate1))
            {
                DateTime dEndDate1 = DateTime.ParseExact(enddate1, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.END_TIME >= dEndDate1);
            }
            if (!string.IsNullOrEmpty(enddate2))
            {
                DateTime dEndDate2 = DateTime.ParseExact(enddate2, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.END_TIME < dEndDate2);
            }

            if (!string.IsNullOrEmpty(pTime1))
            {
                DateTime dPTime1 = DateTime.ParseExact(pTime1, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.P_TIME >= dPTime1);
            }
            if (!string.IsNullOrEmpty(pTime2))
            {
                DateTime dPTime2 = DateTime.ParseExact(pTime2, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.P_TIME < dPTime2);
            }

            pager.totalRows = queryData.Count();
            //排序
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            return TransHelper.TransExpList<V_S_MAKESAMPLE_RL, V_S_MAKESAMPLEModel>(queryData.ToList());
        }
    }
}
